﻿namespace EnergyGeneratorSimVisualizer.ViewModels
{
    using EnergyGeneratorSim.Parameters;

    public class SimulationParametersViewModel : ViewModelBase
    {
        private SimulationParameters simualtionParameters;
        private InductorParametersViewModel inductorParametersVM;
        private PermanentMagnetParametersViewModel permanentMagnetVM;
        private GeneralParametersViewModel generalVM;
        /// <summary>
        /// Initializes a new instance of the <see cref="SimulationParametersViewModel"/> class.
        /// </summary>
        /// <param name="param">The param.</param>
        public SimulationParametersViewModel(SimulationParameters param)
        {
            this.simualtionParameters = param;
            this.inductorParametersVM = new InductorParametersViewModel(param.Inductor);
            this.permanentMagnetVM = new PermanentMagnetParametersViewModel(param.PermanentMagnet);
            this.generalVM = new GeneralParametersViewModel(param.General);
        }

        /// <summary>
        /// Gets the model.
        /// </summary>
        /// <value>The model.</value>
        public SimulationParameters Model
        {
            get { return this.simualtionParameters; }
        }

        /// <summary>
        /// Gets or sets the anz P.
        /// Zum Lösen der Dgl.: Anzahl der tatsächlich berechneten Zeit-Schritte
        /// </summary>
        /// <value>The anz P.</value>
        public ulong AnzP
        {
            get
            {
                return this.simualtionParameters.AnzP;
            }
            set
            {
                this.simualtionParameters.AnzP = value;
                this.NotifyPropertyChanged(x => x.AnzP);
                this.NotifyPropertyChanged(x => x.SimulationsDauer);
            }
        }

        /// <summary>
        /// Gets or sets the dt.
        /// Sekunden} {Zum Lösen der Dgl.: Dauer der Zeitschritte zur iterativen Lsg. der Dgl.
        /// </summary>
        /// <value>The dt.</value>
        public double Dt
        {
            get
            {
                return this.simualtionParameters.dt * 1e9;
            }
            set
            {
                this.simualtionParameters.dt = value / 1e9;
                this.NotifyPropertyChanged(x => x.Dt);
                this.NotifyPropertyChanged(x => x.SimulationsDauer);
            }
        }

        /// <summary>
        /// Gets or sets the simulations dauer.
        /// </summary>
        /// <value>The simulations dauer.</value>
        public double SimulationsDauer
        {
            get
            {
                return this.AnzP * this.Dt / 1e9;
            }

            set
            {
                this.AnzP = (ulong)(value / this.Dt * 1e9);
                this.NotifyPropertyChanged(x => x.SimulationsDauer);
                this.NotifyPropertyChanged(x => x.AnzP);
            }
        }


        /// <summary>
        /// Gets or sets the abstd.
        /// Nur für die Vorbereitung, nicht zum Lösen der Dgl.: Jeden wievielten Punkt soll ich plotten ins Excel
        /// </summary>
        /// <value>The abstd.</value>
        public ulong Abstd
        {
            get
            {
                return this.simualtionParameters.Abstd;
            }
            set
            {
                this.simualtionParameters.Abstd = value;
                this.NotifyPropertyChanged(x => x.Abstd);
            }
        }

        /// <summary>
        /// Gets or sets the plot anfang.
        /// Zum Lösen der Dgl.: Erster-Plot-Punkt: Anfang des Daten-Exports nach Excel
        /// </summary>
        /// <value>The plot anfang.</value>
        public ulong PlotAnfang
        {
            get
            {
                return this.simualtionParameters.PlotAnfang;
            }
            set
            {
                this.simualtionParameters.PlotAnfang = value;
                this.NotifyPropertyChanged(x => x.PlotAnfang);
            }
        }

        /// <summary>
        /// Gets or sets the plot ende.
        /// Zum Lösen der Dgl.: Letzter-Plot-Punkt: Ende des Daten-Exports nach Excel
        /// </summary>
        /// <value>The plot ende.</value>
        public ulong PlotEnde
        {
            get
            {
                return this.simualtionParameters.PlotEnde;
            }
            set
            {
                this.simualtionParameters.PlotEnde = value;
                this.NotifyPropertyChanged(x => x.PlotEnde);
            }
        }

        /// <summary>
        /// Gets or sets the plot step.
        /// Zum Lösen der Dgl.: Schrittweite des Daten-Exports nach Excel
        /// </summary>
        /// <value>The plot step.</value>
        public ulong PlotStep
        {
            get
            {
                return this.simualtionParameters.PlotStep;
            }
            set
            {
                this.simualtionParameters.PlotStep = value;
                this.NotifyPropertyChanged(x => x.PlotStep);
            }
        }

        /// <summary>
        /// Gets the inductor.
        /// </summary>
        /// <value>The inductor.</value>
        public InductorParametersViewModel Inductor
        {
            get { return this.inductorParametersVM; }
        }

        /// <summary>
        /// Gets the permanent magnet.
        /// </summary>
        /// <value>The permanent magnet.</value>
        public PermanentMagnetParametersViewModel PermanentMagnet
        {
            get { return this.permanentMagnetVM; }
        }

        /// <summary>
        /// Gets the general parameters.
        /// </summary>
        /// <value>The general parameters.</value>
        public GeneralParametersViewModel General
        {
            get { return this.generalVM; }
        }
    }
}
